package com.github.catvod.parser;

import android.util.Base64;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.spider.merge.CE;
import com.github.catvod.spider.merge.fP;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import org.json.JSONObject;

/* loaded from: classes.dex */
public class JsonBasic {
    public static HashMap<String, String> getReqHeader(String str) {
        HashMap<String, String> hashMap = new HashMap<>();
        if (str.contains("cat_ext")) {
            try {
                int indexOf = str.indexOf("cat_ext=");
                int indexOf2 = str.indexOf("&", indexOf);
                String str2 = new String(Base64.decode(str.substring(indexOf + 8, indexOf2), 10));
                String str3 = str.substring(0, indexOf) + str.substring(indexOf2 + 1);
                JSONObject jSONObject = new JSONObject(str2);
                if (jSONObject.has("header")) {
                    JSONObject optJSONObject = jSONObject.optJSONObject("header");
                    Iterator<String> keys = optJSONObject.keys();
                    while (keys.hasNext()) {
                        String next = keys.next();
                        hashMap.put(next, optJSONObject.optString(next, ""));
                    }
                }
                hashMap.put("url", str3);
            } catch (Throwable unused) {
            }
        } else {
            hashMap.put("url", str);
        }
        return hashMap;
    }

    public static JSONObject parse(LinkedHashMap<String, String> linkedHashMap, String str) {
        JSONObject BQ;
        try {
            SpiderDebug.log("Load Json Parse Basic...");
            if (linkedHashMap.size() > 0) {
                for (String str2 : linkedHashMap.keySet()) {
                    HashMap<String, String> reqHeader = getReqHeader(linkedHashMap.get(str2));
                    try {
                        String str3 = reqHeader.get("url");
                        reqHeader.remove("url");
                        SpiderDebug.log(str3 + str);
                        BQ = CE.BQ(str, fP.oq(str3 + str, reqHeader));
                    } catch (Throwable th) {
                        SpiderDebug.log(th);
                    }
                    if (BQ != null) {
                        BQ.put("jxFrom", str2);
                        SpiderDebug.log(BQ.toString());
                        return BQ;
                    }
                }
            }
        } catch (Throwable th2) {
            SpiderDebug.log(th2);
        }
        return new JSONObject();
    }
}
